<template>
  <div>
    <el-form-item label="关闭显示标题">
      <el-input v-model="localData.dicData[0].label" />
    </el-form-item>
    <el-form-item label="关闭值">
      <el-input v-model="localData.dicData[0].value" />
    </el-form-item>
    <el-form-item label="打开显示标题">
      <el-input v-model="localData.dicData[1].label" />
    </el-form-item>
    <el-form-item label="打开值">
      <el-input v-model="localData.dicData[1].value" />
    </el-form-item>
    <el-form-item label="标题绑定属性">
      <el-cascader :props="CascaderProps" :options="attrList" v-model="localData.bindLabel" placeholder="请选择属性" filterable clearable :show-all-levels="false">
        <template #default="{ data: opt }">
          <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
        </template>
      </el-cascader>
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'ConfigSwitch',
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      localData: {},
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      }
    }
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal)
      },
      deep: true
    }
  },
  methods: {
    handleDicClear() {
      this.localData.dicData = [
        { label: '', value: '0' },
        { label: '', value: '1' }
      ]
    }
  }
}
</script>
<style lang="scss" scoped>
.dic {
  display: flex;
  margin-bottom: 5px;
}
</style>
